package com.econ.powercloud.ems.service.biz;

import com.econ.powercloud.common.base.facade.enums.StatusType;
import com.econ.powercloud.common.base.facade.exception.CommonRuntimeException;
import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.console.facade.domain.CloudControlVO;
import com.econ.powercloud.ems.rpc.IFeignPowerNodeConsoleClient;
import com.econ.powercloud.ems.util.NetUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/8/5 16:37
 * @Modified by : zjf
 */
@Service
public class CloudControlBizService {

    @Autowired
    private IFeignPowerNodeConsoleClient iFeignPowerNodeConsoleClient;

    /**
     * 获取云端设置信息
     */
    public CloudControlVO getCloudControlInfo(){
        MsgResult<CloudControlVO> msgResult = iFeignPowerNodeConsoleClient.search();
        if(StatusType.OK.getCode() != msgResult.getStatus()){
            throw new CommonRuntimeException(StatusType.FAIL,msgResult.getStatusText());
        }
        return msgResult.getData();
    }

    /**
     * 下发云端控制
     */
    public Integer pushCloudSwitch(Integer onoff){
        MsgResult<Integer> msgResult = iFeignPowerNodeConsoleClient.cloudSwitch(NetUtils.getClientIp(),onoff);
        if(StatusType.OK.getCode() != msgResult.getStatus()){
            throw new CommonRuntimeException(StatusType.FAIL, msgResult.getStatusText());
        }
        if (msgResult.getData() == null) {
            throw new CommonRuntimeException(StatusType.FAIL,"发送失败");
        }
        return msgResult.getData();
    }
}
